package cn.gzsxt.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gzsxt.mapper.provider.RoleProvider;

@Mapper
public interface RoleMapper {
	

	/**
	 * 通过条件返回总记录数
	 * 
	 * @param condition
	 * @return
	 */
	@SelectProvider(type = RoleProvider.class, method = "count")
	long count(Map<String, Object> condition);
	
	/**
	 * 通过编号删除记录
	 * @param roleIds
	 * @return
	 */
	@DeleteProvider(type=RoleProvider.class,method="deleteByIds")
	int deleteByIds(Object... roleIds);

	/**
	 * 查询所有角色数据
	 * 
	 * @return
	 */
	@Select("SELECT * FROM tb_basic_role")
	List<Map<String, Object>> findAll();

	/**
	 * 通过条件分页查询
	 * 
	 * @param condition
	 * @param start
	 *            = index * size （数据库索引从0开始）
	 * @param size
	 * @return
	 */
	@SelectProvider(type = RoleProvider.class, method = "findByConditionAndPage")
	List<Map<String, Object>> findByConditionAndPage(@Param("condition") Map<String, Object> condition,
			@Param("start") int start, @Param("size") int size);

	/**
	 * 通过角色编号查询一条记录
	 * @param roleId
	 * @return
	 */
	@Select("SELECT *	FROM tb_basic_role WHERE ROLE_ID=#{roleId}")
	Map<String,Object> findById(Object roleId);
	
	/**
	 * 插入角色记录
	 * 
	 * @param role
	 * @return
	 */
	@Insert("INSERT INTO tb_basic_role	(ROLE_NAME, ROLE_PERMISSIONS) VALUES (#{ROLE_NAME}, #{ROLE_PERMISSIONS})")
	@Options(useGeneratedKeys = true, keyProperty = "ROLE_ID")
	int insert(Map<String, Object> role);
	
	/**
	 * 更新角色非空的字段
	 * @param admin
	 * @return
	 */
	@UpdateProvider(type=RoleProvider.class,method="updateForNotnull")
	int updateForNotnull(Map<String, Object> role);


}
